﻿// ===============================================================================
// Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
// 作者:张谦
// ===============================================================================

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using XCI.Sys.Service;
using XCI.Extensions;
using XCI.Windows;
using XCI.Helper;

namespace XCI.Sys.Forms
{
    public partial class FrmRevisePassword : BaseForm
    {
        private readonly string _userIds;

        public FrmRevisePassword(string userIds)
        {
            InitializeComponent();
            _userIds = userIds;
        }

        private void FrmRevisePassword_Load(object sender, EventArgs e)
        {
            editPassword.Focus();
        }

        private async void btnSave_Click(object sender, EventArgs e)
        {
            string password = editPassword.Text;
            string confirmPassword = editConfirmPassword.Text;
            if (_userIds.IsEmpty())
            {
                MessageBoxHelper.ShowWarn("请先选择需要重置的用户");
                return;
            }

            if (password.IsEmpty())
            {
                MessageBoxHelper.ShowWarn("请输入新密码");
                editPassword.Select();
                return;
            }

            if (!password.Equals(confirmPassword))
            {
                MessageBoxHelper.ShowWarn("确认密码必须与新密码输入一致");
                editConfirmPassword.Select();
                return;
            }

            await SysAccountService.Instance.RevisePasswordAsync(_userIds, password);
            MessageBoxHelper.ShowMessage("用户密码重置成功");
            DialogOk();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogCancel();
        }
    }
}